"""
@name : statistics_ip
@author : maxueyan
@projectname: sanchuang
"""

import random
import collections
with open("ips.txt","w",encoding="utf-8") as file1:
    for i in range(120000):
        ip = "172.25.254."+str(random.randint(1,255))+"\n"
        file1.write(ip)
#生成一个120000行的大文件ips.txt，随机产生172.25.254.0/24段的ip
with open("ips.txt","r",encoding="utf-8") as file2:
    data = file2.readlines()

s = collections.Counter(data)
#统计次数
s_list = s.most_common(10)
#生成一个列表，提供ip出现频率前10的ip
for key in s_list:
    print("ip:{}  time:{}".format(key[0].rstrip(), key[1]))
